package com.example.clxy.controller;

import com.alibaba.druid.sql.PagerUtils;
import com.example.clxy.entity.Unbind;
import com.example.clxy.entity.dto.LoginUserDto;
import com.example.clxy.entity.dto.UnBindDto;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.PageResult.UnbindPageResult;
import com.example.clxy.result.business.PageResult.UserPageResult;
import com.example.clxy.result.business.UserResult;
import com.example.clxy.service.UserService;
import com.example.clxy.service.WechatBindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author weichong
 * date 2020-08-06
 * @Description:
 */

@RestController
@RequestMapping("WechatBindController")
public class WechatBindController {

    @Autowired
    private WechatBindService wechatBindService;
    @Autowired
    private UserService userService;

    /**
     * 绑定微信
     */
    @RequestMapping("addWechatBind")
    public WebRestResult addWechatBind(String openid, String account, String wxnumber, String wxname) {
        WebRestResult res = wechatBindService.addWechatBind(openid, account, wxnumber, wxname);
        return res;
    }

    /**
     * 申请解绑
     */
    @RequestMapping("addWechatBindApply")
    public WebRestResult addWechatBindApply(@RequestBody Unbind unbind) {
        WebRestResult res = wechatBindService.addWechatBindApply(unbind);
        return res;
    }

    /**
     * 查询所有解绑申请
     */
    @RequestMapping("getWechatBindApply")
    public PageResult<UnbindPageResult> getWechatBindApply(int page, int pagesize) {
        PageResult<UnbindPageResult> res = wechatBindService.getWechatBindApply(page, pagesize);
        return res;
    }

    @RequestMapping("passWechatBindApply")
    public WebRestResult passWechatBindApply(String unbindid) {
        WebRestResult res = wechatBindService.passWechatBindApply(unbindid);
        return res;
    }

    @RequestMapping("refuseWechatBindApply")
    public WebRestResult refuseWechatBindApply(String unbindid, String rejectreason) {
        WebRestResult res = wechatBindService.refuseWechatBindApply(unbindid, rejectreason);
        return res;
    }


    /**
     * 小程序用户绑定
     *
     * @param loginUserDto
     * @return
     */
    @RequestMapping("wxBindUser")
    @CrossOrigin
    public UserResult wxBindUser(@RequestBody LoginUserDto loginUserDto) {
        UserResult result = userService.wxBindUser(loginUserDto);
        return result;
    }

    /**
     * 微信申请解绑
     *
     * @param unBindDto
     * @return
     */
    @RequestMapping("wxApplyUnbind")
    @CrossOrigin
    public WebRestResult wxApplyUnbind(@RequestBody UnBindDto unBindDto) {
        WebRestResult result = wechatBindService.wxApplyUnbind(unBindDto);
        return result;
    }

}
